package com.renren;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.renren.api.connect.android.Renren;
import com.renren.api.connect.android.exception.RenrenAuthError;
import com.renren.api.connect.android.exception.RenrenException;
import com.renren.api.connect.android.feed.FeedPublishRequestParam;
import com.renren.api.connect.android.users.UsersGetInfoRequestParam;
import com.renren.api.connect.android.users.UsersGetInfoResponseBean;
import com.renren.api.connect.android.view.RenrenAuthListener;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
	Button login,fabu;
	Button fenXiangBtn;
	final String appid="185654";
	final String apiKey="456362f1c22d4a66a95befba6efe1147";
	final String secret="aff567563a9c4b84858ea87e048d427c";
	Renren renren;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final String tag=MainActivity.class.getName();
        setContentView(R.layout.main);
        
		Log.d("MainActivity", "onCreate");
		login=(Button) findViewById(R.id.login);
		fabu=(Button) findViewById(R.id.fabu);
		fenXiangBtn=(Button) findViewById(R.id.fenXiangBtn);
		renren = new Renren(apiKey, secret, appid, this);
		
		login.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Log.d(tag, "login");
				//Renren renren = new Renren(apiKey, secret, appid, MainActivity.this);
				renren.authorize(MainActivity.this, new RenrenAuthListener(){

					@Override
					public void onCancelAuth(Bundle arg0) {
						// TODO Auto-generated method stub
						Log.d("MainActivity", "onCancelAuth");
					}

					@Override
					public void onCancelLogin() {
						// TODO Auto-generated method stub
						Log.d("MainActivity", "onCancelLogin");
					}

					@Override
					public void onComplete(Bundle arg0) {
						// TODO Auto-generated method stub
						Log.d("MainActivity", "onComplete");
						Log.d("MainActivity", arg0.toString());
					}

					@Override
					public void onRenrenAuthError(RenrenAuthError arg0) {
						// TODO Auto-generated method stub
						Log.d("MainActivity", "onRenrenAuthError");
					}
					
				});
			}
		});
		//renren.
		fabu.setOnClickListener(new View.OnClickListener() {
			
			

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.d(tag, "fabu");
				//Renren renren = new Renren(apiKey, secret, appid, MainActivity.this);
				renren.getSessionKey();
				String s[]={"450293567"};
				UsersGetInfoRequestParam arg0=new UsersGetInfoRequestParam(s);
				
				try {
					UsersGetInfoResponseBean r = renren.getUsersInfo(arg0);
					Log.d(tag, "");
				} catch (RenrenException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (Throwable e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		fenXiangBtn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.d(tag, "fenXiangBtn");
				//Renren renren = new Renren(apiKey, secret, appid, MainActivity.this);
				// renren = new Renren(apiKey, secret, appid, MainActivity.this);
				
				FeedPublishRequestParam feed =  new FeedPublishRequestParam(
						"标题", 
						"新鲜事主体内容",
						"http://wiki.dev.renren.com/wiki/Widget_API", //新鲜事链接 	
						"http://wiki.dev.renren.com/mediawiki/images/9/96/Feed_dialog_4.png", //新鲜事图片url 
						"副标题", 
						"动作名称", 
						"http://wiki.dev.renren.com/wiki/Widget_API", //动作链接, 
						"");
				try {
					renren.publishFeed(MainActivity.this, feed, null);
				} catch (RenrenException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
		});
    }
}